package com.woniu.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.service.ISysConfigService;
import com.woniu.entity.CreLogin;
import com.woniu.service.CreditUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * 注册控制
 *
 * @author Canaan
 */
@RestController
@Api("用户注册")
public class CreditRegisterController extends BaseController {
    @Autowired
    private CreditUserService creditUserService;

    @Autowired
    private ISysConfigService configService;


    @PostMapping("/register")
    @ApiOperation("注册接口")
    public AjaxResult register(@RequestBody CreLogin creLogin) {
        if (!("true".equals(configService.selectConfigByKey("sys.account.registerUser")))) {
            return error("当前系统没有开启注册功能！");
        }
        String msg = creditUserService.register(creLogin);
        return StringUtils.isEmpty(msg) ? success() : error(msg);
    }
}
